package cn.xxxy.fourm.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.xxxy.fourm.dao.MenuDao;
import cn.xxxy.fourm.entity.Menu;
import cn.xxxy.fourm.entity.User;
import cn.xxxy.fourm.model.Attributes;
import cn.xxxy.fourm.model.Node;
import cn.xxxy.fourm.service.MenuService;
@Service@Transactional
public class MenuServiceImpl implements MenuService{
	@Autowired
	private MenuDao menuDao;
	
	@Override
	public List<Node> lists(int parentId) {
		List<Menu> menus=null;
		if(parentId==0) {
			menus=menuDao.listByParentId(0);
		}else {
			menus=menuDao.listByParentId(parentId);
		}
		List<Node> nodes=new ArrayList<>();
		for (Menu menu : menus) {
			Node node=new Node();
			node.setIconCls(menu.getIconCls());
			node.setId(menu.getId());
			node.setText(menu.getMenuname());
			Attributes attributes=new Attributes();
			attributes.setUrl(menu.getUrl());
			node.setAttributes(attributes);
			List<Menu> childs=menuDao.listByParentId(node.getId());
			if(childs!=null) {
				List<Node> children=lists(node.getId());
				node.setChildren(children);
			}
			nodes.add(node);
		}
		return nodes;
		}
}
